import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
import _regeneratorRuntime from "@babel/runtime/regenerator";
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
var _excluded = ["tenantId"],
    _excluded2 = ["tenantId", "id"],
    _excluded3 = ["tenantId"],
    _excluded4 = ["tenantId"],
    _excluded5 = ["tenantId", "id"],
    _excluded6 = ["tenantId", "ldapHistoryId"];

/**
 * ldapService.js - LDAP service
 * @date: 2018-12-20
 */
import request from 'utils/request';
import { CPAAS_IAM } from 'utils/config';
/**
 * 查询LDAP数据
 * @param {Object} params - 查询参数
 */

export function fetchLDAP(_x) {
  return _fetchLDAP.apply(this, arguments);
}
/**
 * 更新LDAP
 * @param {Object} params
 */

function _fetchLDAP() {
  _fetchLDAP = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(params) {
    return _regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            return _context.abrupt("return", request("".concat(CPAAS_IAM, "/v1/").concat(params.tenantId, "/ldaps"), {
              method: 'GET'
            }));

          case 1:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  }));
  return _fetchLDAP.apply(this, arguments);
}

export function updateLDAP(_x2) {
  return _updateLDAP.apply(this, arguments);
}
/**
 * 连接测试
 * @param {Object} params
 */

function _updateLDAP() {
  _updateLDAP = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(params) {
    var tenantId, others;
    return _regeneratorRuntime.wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            tenantId = params.tenantId, others = _objectWithoutProperties(params, _excluded);
            return _context2.abrupt("return", request("".concat(CPAAS_IAM, "/v1/").concat(tenantId, "/ldaps"), {
              method: 'PUT',
              body: others
            }));

          case 2:
          case "end":
            return _context2.stop();
        }
      }
    }, _callee2);
  }));
  return _updateLDAP.apply(this, arguments);
}

export function testConnect(_x3) {
  return _testConnect.apply(this, arguments);
}
/**
 * 禁用LDAP
 * @param {Object} params
 */

function _testConnect() {
  _testConnect = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(params) {
    var tenantId, id, others;
    return _regeneratorRuntime.wrap(function _callee3$(_context3) {
      while (1) {
        switch (_context3.prev = _context3.next) {
          case 0:
            tenantId = params.tenantId, id = params.id, others = _objectWithoutProperties(params, _excluded2);
            return _context3.abrupt("return", request("".concat(CPAAS_IAM, "/v1/").concat(tenantId, "/ldaps/").concat(id, "/test-connect"), {
              method: 'POST',
              body: others
            }));

          case 2:
          case "end":
            return _context3.stop();
        }
      }
    }, _callee3);
  }));
  return _testConnect.apply(this, arguments);
}

export function disabledLDAP(_x4) {
  return _disabledLDAP.apply(this, arguments);
}
/**
 * 启用LDAP
 * @param {Object} params
 */

function _disabledLDAP() {
  _disabledLDAP = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(params) {
    var tenantId, others;
    return _regeneratorRuntime.wrap(function _callee4$(_context4) {
      while (1) {
        switch (_context4.prev = _context4.next) {
          case 0:
            tenantId = params.tenantId, others = _objectWithoutProperties(params, _excluded3);
            return _context4.abrupt("return", request("".concat(CPAAS_IAM, "/v1/").concat(tenantId, "/ldaps/disable"), {
              method: 'PUT',
              body: others
            }));

          case 2:
          case "end":
            return _context4.stop();
        }
      }
    }, _callee4);
  }));
  return _disabledLDAP.apply(this, arguments);
}

export function enabledLDAP(_x5) {
  return _enabledLDAP.apply(this, arguments);
}
/**
 * 查询数据同步信息
 * @param {Object} params - 查询参数
 */

function _enabledLDAP() {
  _enabledLDAP = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(params) {
    var tenantId, others;
    return _regeneratorRuntime.wrap(function _callee5$(_context5) {
      while (1) {
        switch (_context5.prev = _context5.next) {
          case 0:
            tenantId = params.tenantId, others = _objectWithoutProperties(params, _excluded4);
            return _context5.abrupt("return", request("".concat(CPAAS_IAM, "/v1/").concat(tenantId, "/ldaps/enable"), {
              method: 'PUT',
              body: others
            }));

          case 2:
          case "end":
            return _context5.stop();
        }
      }
    }, _callee5);
  }));
  return _enabledLDAP.apply(this, arguments);
}

export function fetchSyncInfo(_x6) {
  return _fetchSyncInfo.apply(this, arguments);
}
/**
 * 查询数据同步错误信息
 * @param {Object} params - 查询参数
 */

function _fetchSyncInfo() {
  _fetchSyncInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(params) {
    var tenantId, id, others;
    return _regeneratorRuntime.wrap(function _callee6$(_context6) {
      while (1) {
        switch (_context6.prev = _context6.next) {
          case 0:
            tenantId = params.tenantId, id = params.id, others = _objectWithoutProperties(params, _excluded5);
            return _context6.abrupt("return", request("".concat(CPAAS_IAM, "/v1/").concat(tenantId, "/ldaps/").concat(id, "/history"), {
              method: 'GET',
              query: others // responseType: 'text',

            }));

          case 2:
          case "end":
            return _context6.stop();
        }
      }
    }, _callee6);
  }));
  return _fetchSyncInfo.apply(this, arguments);
}

export function fetchSyncErrorInfo(_x7) {
  return _fetchSyncErrorInfo.apply(this, arguments);
}
/**
 * 同步用户
 * @param {Object} params
 */

function _fetchSyncErrorInfo() {
  _fetchSyncErrorInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(params) {
    var tenantId, ldapHistoryId, others;
    return _regeneratorRuntime.wrap(function _callee7$(_context7) {
      while (1) {
        switch (_context7.prev = _context7.next) {
          case 0:
            tenantId = params.tenantId, ldapHistoryId = params.ldapHistoryId, others = _objectWithoutProperties(params, _excluded6);
            return _context7.abrupt("return", request("".concat(CPAAS_IAM, "/v1/").concat(tenantId, "/ldaps/ldap-histories/").concat(ldapHistoryId, "/error-users"), {
              method: 'GET',
              query: others
            }));

          case 2:
          case "end":
            return _context7.stop();
        }
      }
    }, _callee7);
  }));
  return _fetchSyncErrorInfo.apply(this, arguments);
}

export function syncUser(_x8) {
  return _syncUser.apply(this, arguments);
}
/**
 * 停止同步用户
 * @param {Object} params
 */

function _syncUser() {
  _syncUser = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8(params) {
    var tenantId, id;
    return _regeneratorRuntime.wrap(function _callee8$(_context8) {
      while (1) {
        switch (_context8.prev = _context8.next) {
          case 0:
            tenantId = params.tenantId, id = params.id;
            return _context8.abrupt("return", request("".concat(CPAAS_IAM, "/v1/").concat(tenantId, "/ldaps/").concat(id, "/sync-users"), {
              method: 'POST'
            }));

          case 2:
          case "end":
            return _context8.stop();
        }
      }
    }, _callee8);
  }));
  return _syncUser.apply(this, arguments);
}

export function stopSyncUser(_x9) {
  return _stopSyncUser.apply(this, arguments);
}
/**
 * 查询ldap同步离职
 * @param {Object} params - 查询参数
 */

function _stopSyncUser() {
  _stopSyncUser = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9(params) {
    var tenantId, id;
    return _regeneratorRuntime.wrap(function _callee9$(_context9) {
      while (1) {
        switch (_context9.prev = _context9.next) {
          case 0:
            tenantId = params.tenantId, id = params.id;
            return _context9.abrupt("return", request("".concat(CPAAS_IAM, "/v1/").concat(tenantId, "/ldaps/").concat(id, "/stop"), {
              method: 'PUT'
            }));

          case 2:
          case "end":
            return _context9.stop();
        }
      }
    }, _callee9);
  }));
  return _stopSyncUser.apply(this, arguments);
}

export function querySyncLeave(_x10) {
  return _querySyncLeave.apply(this, arguments);
}
/**
 * 更新ldap同步离职
 * @param {Object} params
 */

function _querySyncLeave() {
  _querySyncLeave = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee10(params) {
    var tenantId;
    return _regeneratorRuntime.wrap(function _callee10$(_context10) {
      while (1) {
        switch (_context10.prev = _context10.next) {
          case 0:
            tenantId = params.tenantId;
            return _context10.abrupt("return", request("".concat(CPAAS_IAM, "/v1/").concat(tenantId, "/ldaps/sync-leave-config"), {
              method: 'GET'
            }));

          case 2:
          case "end":
            return _context10.stop();
        }
      }
    }, _callee10);
  }));
  return _querySyncLeave.apply(this, arguments);
}

export function updateSyncLeave(_x11) {
  return _updateSyncLeave.apply(this, arguments);
}
/**
 * 查询ldap同步用户
 * @param {Object} params - 查询参数
 */

function _updateSyncLeave() {
  _updateSyncLeave = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee11(params) {
    var tenantId;
    return _regeneratorRuntime.wrap(function _callee11$(_context11) {
      while (1) {
        switch (_context11.prev = _context11.next) {
          case 0:
            tenantId = params.tenantId;
            return _context11.abrupt("return", request("".concat(CPAAS_IAM, "/v1/").concat(tenantId, "/ldaps/sync-leave-config"), {
              method: 'POST',
              body: params
            }));

          case 2:
          case "end":
            return _context11.stop();
        }
      }
    }, _callee11);
  }));
  return _updateSyncLeave.apply(this, arguments);
}

export function querySyncUser(_x12) {
  return _querySyncUser.apply(this, arguments);
}
/**
 * 更新ldap同步用户
 * @param {Object} params
 */

function _querySyncUser() {
  _querySyncUser = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee12(params) {
    var tenantId;
    return _regeneratorRuntime.wrap(function _callee12$(_context12) {
      while (1) {
        switch (_context12.prev = _context12.next) {
          case 0:
            tenantId = params.tenantId;
            return _context12.abrupt("return", request("".concat(CPAAS_IAM, "/v1/").concat(tenantId, "/ldaps/sync-user-config"), {
              method: 'GET'
            }));

          case 2:
          case "end":
            return _context12.stop();
        }
      }
    }, _callee12);
  }));
  return _querySyncUser.apply(this, arguments);
}

export function updateSyncUser(_x13) {
  return _updateSyncUser.apply(this, arguments);
}

function _updateSyncUser() {
  _updateSyncUser = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee13(params) {
    var tenantId;
    return _regeneratorRuntime.wrap(function _callee13$(_context13) {
      while (1) {
        switch (_context13.prev = _context13.next) {
          case 0:
            tenantId = params.tenantId;
            return _context13.abrupt("return", request("".concat(CPAAS_IAM, "/v1/").concat(tenantId, "/ldaps/sync-user-config"), {
              method: 'POST',
              body: params
            }));

          case 2:
          case "end":
            return _context13.stop();
        }
      }
    }, _callee13);
  }));
  return _updateSyncUser.apply(this, arguments);
}